<meta charset="utf-8">
(#) Target SDK attribute is not targeting latest version

!!! WARNING: Target SDK attribute is not targeting latest version
   This is a warning.

Id
:   `OldTargetApi`
Summary
:   Target SDK attribute is not targeting latest version
Severity
:   Warning
Category
:   Correctness
Platform
:   Android
Vendor
:   Android Open Source Project
Feedback
:   https://issuetracker.google.com/issues/new?component=192708
Since
:   8.2.0 (November 2023)
Affects
:   Gradle build files and manifest files
Editing
:   This check runs on the fly in the IDE editor
See
:   https://developer.android.com/distribute/best-practices/develop/target-sdk.html
See
:   https://developer.android.com/reference/android/os/Build.VERSION_CODES.html
Implementation
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GradleDetector.kt)
Tests
:   [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt)

When your application or sdk runs on a version of Android that is more
recent than your `targetSdkVersion` specifies that it has been tested
with, various compatibility modes kick in. This ensures that your
application continues to work, but it may look out of place. For
example, if the `targetSdkVersion` is less than 14, your app may get an
option button in the UI.

To fix this issue, set the `targetSdkVersion` to the highest available
value. Then test your app to make sure everything works correctly. You
may want to consult the compatibility notes to see what changes apply to
each version you are adding support for:
https://developer.android.com/reference/android/os/Build.VERSION_CODES.html
as well as follow this guide:
https://developer.android.com/distribute/best-practices/develop/target-sdk.html.

!!! Tip
   This lint check has an associated quickfix available in the IDE.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
AndroidManifest.xml:6:Warning: Not targeting the latest versions of
Android; compatibility modes apply. Consider testing and updating this
version. Consult the android.os.Build.VERSION_CODES javadoc for details.
[OldTargetApi]
    &lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="33" /&gt;
                                         -----------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the source file referenced above:

`AndroidManifest.xml`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xml linenumbers
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test.bytecode"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="33" /&gt;

    &lt;application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" &gt;
        &lt;activity
            android:name=".BytecodeTestsActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GradleDetectorTest.kt)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `GradleDetector.testNotTheNewestTargetSdk`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=192708.

(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Adding the suppression attribute `tools:ignore="OldTargetApi"` on
  the problematic XML element (or one of its enclosing elements). You
  may also need to add the following namespace declaration on the root
  element in the XML file if it's not already there:
  `xmlns:tools="http://schemas.android.com/tools"`.

* Using a suppression comment like this on the line above:

  ```kt
  //noinspection OldTargetApi
  problematicStatement()
  ```

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="OldTargetApi" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'OldTargetApi'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore OldTargetApi ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>